package com.nce.service;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springside.modules.orm.Page;
import org.springside.modules.orm.PropertyFilter;

import com.nce.dao.BbsBlogDao;
import com.nce.dao.MblogDao;
import com.nce.dao.NewsDao;
import com.nce.dao.ReportDao;
import com.nce.dao.UserLastCheckTimeDao;
import com.nce.entity.BbsBlog;
import com.nce.entity.Mblog;
import com.nce.entity.News;
import com.nce.entity.Report;
import com.nce.entity.UserLastCheckTime;

@Component
@Transactional
public class SearchService {

	@SuppressWarnings("unused")
	private static Logger logger = LoggerFactory.getLogger(SearchService.class);
	
	@Autowired
	private NewsDao newsDao;
	
	@Autowired
	private MblogDao mblogDao;
	
	@Autowired
	private BbsBlogDao bbsBlogDao;
	
	@Autowired
	private UserLastCheckTimeDao userLastcheckTimeDao;
	
	@Autowired
	private ReportDao reportDao;

	public Page<News> searchNews(Page<News> newsPage,
			List<PropertyFilter> filters) {
		return newsDao.findPage(newsPage, filters);
	}

	public Page<BbsBlog> searchBbsBlog(Page<BbsBlog> bbsBlogPage,
			List<PropertyFilter> filters) {
		return bbsBlogDao.findPage(bbsBlogPage, filters);
	}

	public Page<Mblog> searchMblog(Page<Mblog> mblogPage,
			List<PropertyFilter> filters) {
		return mblogDao.findPage(mblogPage, filters);
	}

	
	public UserLastCheckTime getUseLastCheckTime(Long uid) {
		return userLastcheckTimeDao.findUniqueBy("user.id", uid);
	}

	public List<News> searchNews(List<PropertyFilter> filters) {
		return newsDao.find(filters);
	}

	public List<BbsBlog> searchBbsblog(List<PropertyFilter> filters) {
		return bbsBlogDao.find(filters);
	}
	
	public List<Mblog> searchMblog(List<PropertyFilter> filters) {
		return mblogDao.find(filters);
	}

	public void saveUserLastCheckTime(UserLastCheckTime userLastCheckTime) {
		userLastcheckTimeDao.save(userLastCheckTime);
		
	}
	
	public void saveReport(Report report){
		reportDao.save(report);
	}

	public Page<Report> findReports(List<PropertyFilter> filters ,Page<Report> page) {
		return reportDao.findPage(page, filters);
	}
	
	
}
